package com.fenxiangle.yueding.feature.mine.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fenxiangle.yueding.R;
import com.fenxiangle.yueding.entity.bo.AliPayBo;
import com.fenxiangle.yueding.entity.bo.MyAccountBo;
import com.fenxiangle.yueding.feature.focus.view.WithdrawDepositActivity;
import com.fenxiangle.yueding.feature.publish.contract.PayContract;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.DaggerPayComponent;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.PayPresenterModule;
import com.suozhang.framework.framework.BaseActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyCreditActivity extends BaseActivity implements PayContract.View {
    @BindView(R.id.btn_show_money)
    TextView mBtnShowMoney;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.btn_credit_recharge)
    RelativeLayout mBtnCreditRecharge;
    @BindView(R.id.btn_credit_withdraw)
    RelativeLayout mBtnCreditWithdraw;
    MyAccountBo mData;
    @BindView(R.id.tv_dongjie)
    TextView mTvDongjie;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_my_credit;
    }

    @Inject
    PayContract.Presenter mPresenter;

    @Override
    protected void initInjector() {
        DaggerPayComponent.builder().payPresenterModule(new PayPresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "我的信用金", true, true);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onStart() {
        super.onStart();
        mPresenter.getMyAccount();
    }

    @Override
    public void showAliPayData(String aliPayData) {

    }

    @Override
    public void showWxPayData(AliPayBo.WechatBo wechatBo) {

    }

    @Override
    public void showError(String error) {
        showMsg(error);
    }

    @Override
    public void showAccountSuccess(MyAccountBo aliPayData) {
        mData = aliPayData;
        mBtnShowMoney.setText(aliPayData.getCredit()+ "元");
        mTvDongjie.setText("信用金已冻结￥"+aliPayData.getFrozenCredit()+",如无违约如数返还");
    }


    @OnClick({R.id.btn_credit_recharge, R.id.btn_credit_withdraw})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_credit_recharge:
                startActivity(new Intent(this, RechargeCreditActivity.class));
                break;
            case R.id.btn_credit_withdraw:
                Intent intent = new Intent(this, WithdrawDepositActivity.class);
                intent.putExtra("extensionBo", mData.getCredit() + "");
                intent.putExtra("commissionType", 2);
                startActivityForResult(intent, 30000);
                break;
        }
    }

}
